/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.security.token.common;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * access token
 *
 * @auther ebert_chan
 */
public class AccessToken implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * access token string value
     */
    private String value;

    /**
     * access raw data value
     */
    private Map<String, Object> rawValue;

    /**
     * token expire duration
     */
    private Integer expiresIn;

    /**
     * token expire time
     */
    private Date expiration;

    // constructor

    public AccessToken() {
    }

    public AccessToken(String value) {
        this(value, null, null);
    }

    public AccessToken(String value, Map<String, Object> rawValue) {
        this(value, rawValue, null);
    }

    public AccessToken(String value, Map<String, Object> rawValue, Integer expiresIn) {
        this.value = value;
        this.rawValue = rawValue;
        this.expiresIn = expiresIn;
    }

    // getter and setter

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Map<String, Object> getRawValue() {
        return rawValue;
    }

    public void setRawValue(Map<String, Object> rawValue) {
        this.rawValue = rawValue;
    }

    public Integer getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Integer expiresIn) {
        this.expiresIn = expiresIn;
    }

    public Date getExpiration() {
        return expiration;
    }

    public void setExpiration(Date expiration) {
        this.expiration = expiration;
    }

    public boolean isExpired() {
        return expiration != null && expiration.before(new Date());
    }

}
